package ycl.common.utils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ycl.common.base.entity.BaseEntity;
import ycl.common.models.base.BaseQuery;

/**
 * 分页工具
 *
 * @author YCL
 * @date 2021-08-31 21:05:27
 */
public class PageUtil {


	/**
	 * 获取分页
	 *
	 * @param query 分页查询数据
	 * @param t     分页的泛型类
	 * @param <T>   任意类
	 * @return 分页
	 */
	public static <T> Page<T> getPage(BaseQuery query, Class<T> t) {
		int current = query.getCurrent();
		int size = query.getSize();

		if (current < 1) current = 1;
		if (size < 1) size = 10;
		return new Page<>(current, size);
	}

	public static <T> Page<T> getPage(BaseEntity entity, Class<? extends BaseEntity> t) {
		int current = entity.getCurrent();
		int size = entity.getSize();
		if (current < 1) current = 1;
		if (size < 1) size = 10;
		return new Page<>(current, size);
	}


}
